<?
/***********************************************************/
/* Dialog class, shows messages to the users
/* by Pablo Dall'Oglio 2001-2006
/***********************************************************/
class Dialog
{
    /***********************************************************/
    /* Constructor Method
    /***********************************************************/
    function Dialog($mensagem, $erro = true, $kill = false)
    {
        if (!is_array($mensagem))
        {
            $mensagem = ereg_replace("\r", ' ', $mensagem);
            $mensagem = ereg_replace("\n", ' ', $mensagem);
            if (strlen($mensagem) >40)
            {
            $msgs = explode(' ', $mensagem);
            $n = 0;
            foreach ($msgs as $msg)
            {
                $result[$n] .= ' ' . $msg;
                if (strlen($result[$n]) > 40)
                $n ++;
            }
            $mensagem = $result;
            }
        }
        $this->ShowMessage($mensagem, $erro, $kill);
    }

    /***********************************************************/
    /* Creates the Message Window
    /***********************************************************/
    function ShowMessage($labels, $erro, $kill)
    {
        $this->window = new GtkWindow;
        $this->window->set_position(GTK_WIN_POS_CENTER);
        $this->window->set_modal(true);
        $this->window->set_border_width(10);
        $this->window->realize();
        $this->window->connect_simple('key_press_event', array(&$this,'KeyTest'), null);

        
        $pixwid = GtkImage::new_from_file(images . 'ico_message.xpm');
        
        if ($erro)
            $col1 = &new GdkColor(56000, 0, 0);
        else
            $col1 = &new GdkColor(0, 0, 56000);
        
        $col2 = &new GdkColor(0, 56000, 32000);
        $style = &new GtkStyle;
       // $style->fg[Gtk::_STATE_NORMAL] = $col1;
       // $style->base[Gtk::_STATE_NORMAL] = $col2;
       // $style->font = Gdk::font_load ("-*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*");
        
        $vbox = new GtkVBox(false, 10);
        $this->window->add($vbox);
        
        $hbox = new GtkHBox(false, 10);
        $hbox->pack_start($pixwid);
        
        $textbox = new GtkVBox;
        $hbox->pack_start($textbox);
        
        if (is_array($labels))
        {
            foreach($labels as $lb)
            {
                $tmp = new GtkHBox;
                $line = new GtkHBox;
                $texto = new GtkLabel(' ' . $lb . ' ');
                $texto->set_justify(GTK_JUSTIFY_LEFT);
                $texto->set_style($style);
                $line->pack_start($texto, false, false);
                $line->pack_start($tmp, true, true);
                $textbox->pack_start($line, false, false);
            }
        }
        else
        {
            $texto = new GtkLabel(' ' . $labels . ' ');
            $texto->set_justify(GTK_JUSTIFY_LEFT);
            $texto->set_style($style);
            $textbox->pack_start($texto, false, false);
        }
        
        $sep = new GtkHSeparator;
        
        $vbox->pack_start($hbox);
        $vbox->pack_start($sep);
        
        $hbox = new GtkHBox;
        $this->button = $button = new GtkButton('   ' . _a('Close') . '   ');
        
        if ($kill)
        { $button->connect_simple('clicked', array(&$this, 'Quit')); }
        else
        { $button->connect_simple('clicked', array(&$this, 'Close')); }

        $hbox->pack_start($button, true, false);
        $vbox->pack_start($hbox, true, true);
        $this->window->show_all();
    }

    /***********************************************************/
    /* Closes the window
    /***********************************************************/
    function Close()
    {
        $this->window->hide();
    }

    /***********************************************************/
    /* Kills the entire application
    /***********************************************************/
    function Quit()
    {
        Gtk::main_quit();
    }

    /***********************************************************/
    /* Key Test Method
    /***********************************************************/
    function KeyTest($p1)
    {
        if (($p1->keyval == K_ENTER) or ($p1->keyval == K_ESC) or ($p1->keyval == K_SPACE))
        {
            $this->button->clicked();
        }
    }
}
?>